package com.sskj.cndragon.ui.activity;


import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;

import com.sskj.cndragon.R;
import com.sskj.cndragon.component.DaggerUserDataComponent;
import com.sskj.cndragon.presenter.AccountSafeActivityPresenter;
import com.sskj.cndragon.view.ToolBarLayout;
import com.sskj.common.base.App;
import com.sskj.common.util.ClickUtil;
import com.sskj.common.util.ImageUtil;
import com.sskj.lib.Constans;
import com.sskj.lib.base.BaseActivity;
import com.sskj.lib.bean.UserData;
import com.sskj.lib.model.room.UserViewModel;
import com.sskj.lib.util.HideUtil;

import javax.inject.Inject;

import butterknife.BindView;
import butterknife.ButterKnife;


public class AccountSafeActivity extends BaseActivity<AccountSafeActivityPresenter> {
    @BindView(R.id.toolbar)
    ToolBarLayout toolbar;
    @BindView(R.id.tv_mobile)
    TextView tvMobile;
    @BindView(R.id.tv_login_pwd)
    TextView tvLoginPwd;
    @BindView(R.id.tv_pay_pwd)
    TextView tvPayPwd;
    @BindView(R.id.tv_login_type)
    TextView tvLoginType;
    @BindView(R.id.tv_pay_type)
    TextView tvPayType;
    @Inject
    UserViewModel userViewModel;

    private UserData userData;

    @Override
    protected int getLayoutResId() {
        return R.layout.activity_account_safe;
    }

    @Override
    public AccountSafeActivityPresenter getPresenter() {
        return new AccountSafeActivityPresenter();
    }

    @Override
    protected void initView() {
        super.initView();
        DaggerUserDataComponent.create().inject(this);
        toolbar.setLeftButtonOnClickListener(view -> finish());
    }

    @Override
    protected void initData() {
        super.initData();
        userViewModel.getUsers().observe(this, users -> {
            if (users != null && users.size() > 0) {
                userData = users.get(0);
            } else {
                userData = null;
            }
            if (userData != null) {
                tvMobile.setText(HideUtil.getPhoneHide(userData.getTel()));
                if (userData.getChinaPwd() == 0) {
                    tvPayType.setText(App.INSTANCE.getString(R.string.appWeishezhi));
                    ClickUtil.click(300, tvPayPwd, () -> {
                        ChangePwdActivity.start(this, Constans.PAY_TYPE,userData.getTel());
                    });
                } else {
                    tvPayType.setText(App.INSTANCE.getString(R.string.xiugai));
                    ClickUtil.click(300, tvPayPwd, () -> {
                        ChangePwdActivity.start(this, Constans.PAY_EDIT_TYPE,userData.getTel());
                    });
                }
                ClickUtil.click(300, tvLoginPwd, () -> {
                    ChangePwdActivity.start(this, Constans.LOGIN_TYPE,userData.getTel());
                });
            }
        });
    }

    public static void start(Context context) {
        Intent intent = new Intent(context, AccountSafeActivity.class);
        context.startActivity(intent);
    }
}
